//
//  StudyReportVC.m
//  doubleEduStudents
//
//  Created by 盛洋 on 2021/1/11.
//  Copyright © 2021 shengYang. All rights reserved.
//

#import "StudyReportVC.h"
#import "studyReportCell.h"
#import "ProtocolInforVC.h"

@interface StudyReportVC ()<UITableViewDelegate,UITableViewDataSource>
@property (strong, nonatomic) IBOutlet GlobalTabel *table;
@property (strong, nonatomic) IBOutlet UILabel *tip_lab;

@end

@implementation StudyReportVC
{
    RequestServices *service;
    NSMutableArray *list_arr;
    NSInteger page;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"学习报告";
    [self.backKuang setHidden:YES];
    self.tip_lab.font = AutoLabFont2;
    self.table.delegate = self;
    self.table.dataSource = self;
    self.table.tableFooterView = [UIView new];
    [self.table registerNib:[UINib nibWithNibName:@"studyReportCell" bundle:nil] forCellReuseIdentifier:@"studyReportCell"];
    service = [[RequestServices alloc]initWithDelegate:self];
    service.view = self.view;
    list_arr = [NSMutableArray array];
    [self headerRefresh];
    self.table.mj_header = [MJRefreshHeader headerWithRefreshingBlock:^{
        [self headerRefresh];
    }];
    self.table.mj_footer = [MJRefreshFooter footerWithRefreshingBlock:^{
        [self footReFresh];
    }];
    self.table.mj_footer.hidden = YES;
}

-(void)headerRefresh{
    page = 1;
    [service studyRepoetList:[NSString stringWithFormat:@"%ld",page] tag:8000];
}

-(void)footReFresh{
    page ++;
    [service studyRepoetList:[NSString stringWithFormat:@"%ld",page] tag:8001];
}

-(void)getFinished:(NSDictionary *)obj tag:(long long)tag{
    [self HideLoading];
    [self.table.mj_header endRefreshing ];
    [self.table.mj_footer endRefreshing];
    if (tag == 8000 ) {
        list_arr = [StudyReportModel mj_objectArrayWithKeyValuesArray:obj[@"list"]];
    }
    if (tag == 8001) {
        NSArray *arr = [StudyReportModel mj_objectArrayWithKeyValuesArray:obj];
        [list_arr addObjectsFromArray:arr];
    }
    [self.table reloadData];
}

-(void)getError:(NSError *)error tag:(long long)tag{
    [self HideLoading];
    [self.table.mj_header endRefreshing ];
    [self.table.mj_footer endRefreshing];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return list_arr.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return Is_iPhone ? 80 : 160;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    studyReportCell *cell = [tableView dequeueReusableCellWithIdentifier:@"studyReportCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model = list_arr[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    StudyReportModel *model = list_arr[indexPath.row];
    ProtocolInforVC *vc = [[ProtocolInforVC alloc]init];
    vc.url = model.url;
    [self PushToViewController:vc];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
